﻿<%@ WebHandler Language="C#" Class="SYS_Category_sel" %>

using System;
using System.Web;
using System.Web.Script.Serialization;
using System.Data;
using System.Collections.Generic;
using System.Web.SessionState;

public class SYS_Category_sel : IHttpHandler,IRequiresSessionState {
    sqlhelp sql = new sqlhelp();
    SYS_Categoryresult result = new SYS_Categoryresult();
    string str = "";
    DataTable dt = new DataTable();
    List<SYS_Category> SYS_CategoryList = new List<SYS_Category>();
	string sort = "createTime";
    string sorttype = "desc";
    public void ProcessRequest (HttpContext context) {
        try
        {
            if (context.Session["comid"] == null)
            {
                result.code = "-1";
                result.msg = "用户未登录";
                unit.send(context, result);
                return;
            }
            
            result.code = "1";
            string where = " and Enable = 1 ";
            
            string Id = "";
            if(context.Request["Id"] != null ){
                Id = context.Request["Id"].ToString();
                where = where + " and Id = '"+Id+"'";
            }
            string StoreId = context.Session["comid"].ToString();
            where = where + " and StoreId = '" + StoreId + "'";
            
            string Code = "";
            if(context.Request["Code"] != null ){
                Code = context.Request["Code"].ToString();
                where = where + " and Code = '" + Code + "'";
            } 
            string Name = "";
            if(context.Request["Name"] != null ){
                Name = context.Request["Name"].ToString();
                where = where + " and Name like '%" + Name + "%'";
            } 

            //dt = sql.GetPermissionsPager(sort, sorttype, pageIndex, 10, where, "SYS_Category").Tables[0];
            dt = sql.myDataSet("select * from SYS_Category where 1 = 1 " + where).Tables[0];
            result.total = sql.GetCount("SYS_Category", where);        
			int len = dt.Rows.Count;
			if (len > 0)
			{
				for (int i = 0; i < len; i++) {
					SYS_Category _SYS_Category = new SYS_Category();
					_SYS_Category.Id = dt.Rows[i]["Id"].ToString();
                    _SYS_Category.StoreId = dt.Rows[i]["StoreId"].ToString();
                    _SYS_Category.Code = dt.Rows[i]["Code"].ToString();
                    _SYS_Category.Name = dt.Rows[i]["Name"].ToString();
                    _SYS_Category.CreateTime = dt.Rows[i]["CreateTime"].ToString();
                    _SYS_Category.Enable = dt.Rows[i]["Enable"].ToString();
					SYS_CategoryList.Add(_SYS_Category);
				}
				result.data = SYS_CategoryList;
			}

            }
            catch (Exception e1)
            {
                result.code = "0";
                result.msg = e1.Message;
            }
        unit.send(context, result);
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}

public class SYS_Categoryresult : result
{
    public List<SYS_Category> data = new List<SYS_Category>();
    public int total = 0;

}

public class SYS_Category {
    public string Id = "";
    public string StoreId = "";
    public string Code = "";
    public string Name = "";
    public string CreateTime = "";
    public string Enable = "";
}
